<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="/easyui.css">
    <link rel="stylesheet" type="text/css" href="/icon.css">
    <link rel="stylesheet" type="text/css" href="/demo.css">
    <script src="/jquery.min.js"></script>
    <script src="/jquery.easyui.min.js"></script>
    <title>年级班级树</title>
    <script type="text/javascript">
        <!--获取地址栏参数-->
        function GetQueryString(name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]); return null;
        }
        var tid = GetQueryString("tid");
        if(tid == null){
            tid = 2;
        }
    </script>
</head>
<body class="easyui-layout" data-options="fit:true">
    <div data-options="region:'west'" style="width: 150px;padding-top: 70px">
        <ul id="ul"></ul>
    </div>
    <div data-options="region:'center'" style="padding: 70px;">
        <table id="dg" ></table>
    </div>
    <div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editFenshu()">编辑分数</a>
</div>
<!--表单以及弹窗的定义-->
<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
     closed="true" buttons="#dlg-buttons">
    <div style="color: skyblue">分数</div><hr />
    <form id="form">
        <table cellpadding="5">
            <tr>
                <td>学号：</td>
                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="number" name="sid" id="sid" ></td>
            </tr>
            <tr>
                <td>姓名:</td>
                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="text" name="sname" id="sname" ></td>
            </tr>
            <tr>
                <td>性别：</td>
                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="text" name="ssex" id="ssex" ></td>
            </tr>
            <tr>
                <td>班级编号：</td>
                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="text" name="bid" id="bid" ></td>
            </tr>
            <tr>
                <td>考试科目：</td>
                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="text" name="kname" id="kname" ></td>
            </tr>
            <tr>
                <td>分数：</td>
                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="number" name="fenshu" id="fenshu" ></td>
            </tr>
            <tr>
                <td>考试类型:</td>
                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="text" name="kaoslx" id="kaoslx" ></td>
            </tr>
        </table>
    </form>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="savefenshu()">Save</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
    </div>
</div>

<script type="text/javascript">

    <!--tree加载-->
    $.post('/NBTreeController/treeDate',{tid:tid},function (data) {
        console.log(data);
        $("#ul").tree({
            data:data,
            onLoadSuccess:function () {
                $("#dg").datagrid({
                    url:'/NBTreeController/datagridDate',
                    singleSelect:true,
                    toolbar:'#toolbar',
                    rownumber:'true',
                    queryParams:{bid:data[0].children[0].id},
                    fitColumns:'true',
                    columns:[[
                        {field:'sid',title:'学号',with:100},
                        {field:'sname',title:'姓名',width:100},
                        {field:'ssex',title:'性别',width:100},
                        {field:'bid',title:'班级号',width:100},
                        {field:'kname',title:'考试科目',width:100},
                        {field:'fenshu',title:'分数',width:100},
                        {field:'kaoslx',title:'考试类型',width:100}
                    ]]
                });
            },
            onClick:function (node) {
                $("#dg").datagrid('reload',{bid:node.id});
            }
        });
        var nod = $("#ul").tree('find',4)
        $("#ul").tree('select',nod.target);

    });
    $("#dlg").dialog({});
    $("#form").form({});
    function editFenshu() {
        var row = $("#dg").datagrid('getSelected');
        if(row){
            $("#dlg").dialog('open').dialog('setTitle','Edit FenShu');
            $("#sid").textbox('readonly',true);
            $("#sname").textbox('readonly',true);
            $("#ssex").textbox('readonly',true);
            $("#bid").textbox('readonly',true);
            $("#kname").textbox('readonly',true),
            $("#kaoslx").textbox('readonly',true);
            $("#form").form('load',{
                sid:row.sid,
                sname:row.sname,
                ssex:row.ssex,
                bid:row.bid,
                kname:row.kname,
                fenshu:row.fenshu,
                kaoslx:row.kaoslx,
            });
        }
    }
    function savefenshu() {
        $("#form").form('submit',{
            url:'/NBTreeController/updatafenshu',
            success:function(result){
                $("#dlg").dialog('close');
                $("#dg").datagrid('reload');
            }
        }) ;
    }
</script>

</body>
</html>